"""Setup the digvcs application"""
import logging
from sqlalchemy.orm import *

from digvcs.config.environment import load_environment
from digvcs.model import meta
from digvcs.model.timedim import import_time_dimension
from digvcs.model.datedim import import_date_dimension
from digvcs.model.svnrepo import import_repository

log = logging.getLogger(__name__)

def setup_app(command, conf, vars):
    """Place any commands to setup digvcs here"""
    load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist 
    meta.metadata.create_all(bind=meta.engine)
    
    # Load data 
    session = sessionmaker(bind=meta.engine, autoflush=False, autocommit=True)()

    import_repository(session, 'http://digvcs.googlecode.com/svn')
    import_time_dimension(session)
    import_date_dimension(session, [2009, 2010])
